package cn.xopencode.recordservice.service.pdroom;

import cn.xopencode.recordservice.convert.pdroom.PowerDistributionRoomConvert;
import cn.xopencode.recordservice.dal.mysql.dataobject.pdroom.PowerDistributionRoomDO;
import cn.xopencode.recordservice.dal.mysql.mapper.pdroom.PowerDistributionRoomMapper;
import cn.xopencode.recordservice.service.pdroom.bo.PowerDistributionRoomBO;
import cn.xopencode.recordservice.service.pdroom.bo.PowerDistributionRoomCreateBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.Date;
import java.util.List;

/**
 * 配电室管理 service
 */
@Service
@Validated
public class PowerDistributionRoomService {

    @Autowired
    private PowerDistributionRoomMapper powerDistributionRoomMapper;

    public Integer createPowerDistributionRoom(PowerDistributionRoomCreateBO createBO){
        PowerDistributionRoomDO roomDO = PowerDistributionRoomConvert.INSTANCE.convert(createBO);
        roomDO.setCreateTime(new Date());
        roomDO.setUpdateTime(new Date());
//        roomDO.setModifierId(UserSecurityContextHolder.getUserId());
//        roomDO.setCreatorId(UserSecurityContextHolder.getUserId());
        return powerDistributionRoomMapper.insert(roomDO);
    }

    public List<PowerDistributionRoomBO> getPowerDistributionRoomList(String roomName){
        List<PowerDistributionRoomDO>  roomDOList = powerDistributionRoomMapper.selectLikeRoomName(roomName);
        List<PowerDistributionRoomBO> roomBOList = PowerDistributionRoomConvert.INSTANCE.convertList(roomDOList);
        return roomBOList;
    }
}
